/**
 * 所有版权归 广西梧州 陈锦韬 所有
 *
 * @Title: RxDataRegister
 * @Package com.rx.core.bean
 * @Description: RxData 注册
 * @author: 陈锦韬
 * @date: 2020\8\9 0009
 * @version V1.0
 * @Copyright: 2020 陈锦韬  All rights reserved.
 */
package com.rx.core.handler;

import com.rx.core.base.RxBaseConstant;
import com.rx.core.base.RxRegister;
import com.rx.core.enm.RX_LOG_MODE;
import com.rx.core.util.EmptyChecker;
import com.rx.core.util.RxUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @author: Administrator
 * @Description: RxData 注册
 * @date: 2020\8\9 0009
 */
@Slf4j
public class RxHandlerRegister extends RxRegister implements ImportBeanDefinitionRegistrar, ResourceLoaderAware, EnvironmentAware {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
                                        BeanDefinitionRegistry registry) {

        String[] basePackages = getPackages(importingClassMetadata,
                RxBaseConstant.DEFALUT_PKG_HANDLER,
                RxHandlerScan.class.getName());

        if (EmptyChecker.isEmpty(basePackages)){
            return;
        }
        importingClassMetadata.getAnnotations();

        log.info(RX_LOG_MODE.ANN_HANDLER.getFormat("开始扫描"));
        log.info(RX_LOG_MODE.DEFAULT.getFormat(RxUtil.toJsonString(basePackages)),"扫描路径");
        //扫描类
        RxHandlerScanner.scan(registry,basePackages);
        log.info(RX_LOG_MODE.ANN_HANDLER.getFormat("扫描完成\n"));

    }

    @Override
    public void setEnvironment(Environment environment) {
        this.environment = environment;
    }

    @Override
    public void setResourceLoader(ResourceLoader resourceLoader) {
        this.resourceLoader = resourceLoader;
    }
}


